package com.demo.datastructure.reorder;

import com.demo.datastructure.reorder.quickSort.SimpleQuickSort5;

/**
 * @description: 算法4 2.1 排序算法类的模板
 * @author: ljr
 * @time: 2021/7/23 15:44
 */
public interface Example {

    default void sort(Comparable[] a){

    };

    default void sort(Comparable[] a, int low, int high){

    };

    default boolean less(Comparable v, Comparable w){
        return v.compareTo(w) < 0;
    }

    default boolean lessa(int j, int h,  Comparable v, Comparable w){
        if(v == null){
            System.out.println("j=========="+j);
        }

        if(w == null){
            System.out.println("h=========="+h);
        }
        return v.compareTo(w) < 0;
    }

    default void exch(Comparable[] a, int i , int j){
         Comparable t = a[i];
         a[i] = a[j];
         a[j] = t;
    }

    default void show(Comparable[] a){
        for(int i = 0; i < a.length; i++){
            System.out.print(a[i]+"");
            System.out.println();
        }
    }

    //判断是否有序
    default boolean isSorted(Comparable[] a){
        for(int i = 1; i < a.length; i++){
            if(less(a[i], a[i-1])){
                return false;
            }
        }
        return true;
    }

    static void main(String[] args) {
//        Random random = new Random();
//        Comparable[] nums = new Comparable[1000000];
//        for(int i = 0; i < 1000000; i++){
//            nums[i] = random.nextInt(1000);
//        }

//   Comparable[] nums = new Comparable[]{
//                "S","H","E","L","L","S","O","R","T","E","X","A","M","P","L","E"};

        Comparable[] nums = new Comparable[]{
                2, 2, 1, 3, 4, 4, 2, 1, 3, 4};
        Example example = new SimpleQuickSort5();
        example.sort(nums, 0, nums.length-1);
        assert example.isSorted(nums);
        example.show(nums);
    }
}
